#include <iostream>
#include<string>
#include<cstdlib>
using namespace std;

int main() {
    int  b = 0, c, e;
    int i;
    string a;
    while (cin >> a)
    {
        b = 0;
        if (a.length() < 2)
            b = a[0] - '0';

        else
        {
            for (i = a.length() - 1; i >= 0; --i)
            {
                c = a[i] - '0';
                b += c;
            }

            while (b >= 10)
            {
                e = b;
                b = 0;
                while (e >= 10)
                {
                    c = e % 10;

                    e = e / 10;
                    b += c;
                }
                b += e;

            }
        }

        cout << b << endl;
    }

}